Skip to content

Savannah#18

Open
qqdipps wants to merge 3 commits intoAda-C11:masterfrom
qqdipps:master
Open

Savannah#18
qqdipps wants to merge 3 commits intoAda-C11:masterfrom
qqdipps:master

Conversation

@qqdipps
Copy link
Copy Markdown

@qqdipps qqdipps commented Sep 5, 2019

No description provided.

Copy link
Copy Markdown

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done, you hit the learning goals here. Do look at my comments on Big-O. I liked the helper methods you wrote and how you did the height methods. Great work!

# Time Complexity:
# Space Complexity:
# Time Complexity: O(log(n)) where n is the number of nodes
# Space Complexity: O(1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember since you're doing this recursively, the system stack will allocate space for each recursive call.

So if the tree is balanced the space complexity is O(log n), if it's widely unbalanced O(n). The same also applies to time complexity.

return 0 if !node
right = longest_tree_path(node.right)
left = longest_tree_path(node.left)
return [right, left].max + 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clever!

# Time Complexity:
# Space Complexity:
# Time Complexity: O(n) where n is the number of nodes
# Space Complexity: O(n)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The space complexity will be O(n) if the tree is unbalanced (due to the system stack) or O(log n) if the tree is balanced.

# Space Complexity:
# Time Complexity: O(n) where n is the number of nodes
# Space Complexity: O(n) ""
def bfs
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Niiiice!

end
end

describe "hieght" do
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I will use these for C12, if that's ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants